/**
 */
import {getAction, postAction} from '@/api/manage'

export const butStatus = {
  data() {
    return {
      // 2 为待审核，9 为已审核
      status: '',

      approveStatus: '',
      dataSource: []
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    showShjl() {
      this.$refs.shjlModal.show()
    },
    loadData() {
      this.loading = true
      this.dataSource = []
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!")
        return
      }
      var params = this.getQueryParams();//查询条件
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          if (res.result.records || Array.isArray(res.result)) {
            this.status = res.applyStatus
            this.dataSource = res.result.records || res.result;
            if (res.result.total) {
              this.ipagination.total = res.result.total;
            } else {
              this.ipagination.total = 0;
            }
          } else {
            this.status = res.result[this.statusKey].status
            console.info('🚀 ~ line:43 -----', this.status)

            if(res.result[this.statusKey].records){
              this.dataSource = res.result[this.statusKey].records
            }else{
              this.dataSource.push(res.result[this.statusKey])
            }

           /* if (res.result.cg.id != undefined) {
              this.dataSource.push(res.result[this.statusKey])
            }*/
          }
        } else {
          this.$message.error(res.message)
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false;
      })
    },
    // 提交审核-打开选择审核人弹窗
    showConfirm() {
      if (this.dataSource.length == 0) {
        this.$message.warning("请添加数据!")
        return
      }
      this.$refs.approver.show()
    },
    // 提交审核
    handleSubmit(userId) {
      getAction(this.url.submit, {
        proId: this.id,
        userId: userId,
        typeId: this.typeId
      }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
          this.list1()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    // 填写审核原因
    setApproveReason(status) {
      this.approveStatus = status
      this.$refs.setReason.show()
    },
    // 同意拒绝
    approveData(reason) {
      let remark = this.approveStatus === '9' ? `同意：${reason}` : `拒绝：${reason}`
      getAction(this.url.approve, {
        proId: this.id,
        status: this.approveStatus,
        remark: remark,
        typeId: this.typeId
      }).then((res) => {
        if (res.success) {
          this.$refs.setReason.setApproveReason = false
          this.loadData()
          this.list1()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    //报告
    handleImportExcel2(info) {
      if (info.file.status === 'done') {
        if (info.file.response.success) {
          this.$message.success(info.file.response.message || `${info.file.name} 文件上传成功`)
          this.saveBg(info.file.response.result[0].id, this.bgType)
        } else {
          this.$message.error(`${info.file.name} ${info.file.response.message}.`);
        }
      } else if (info.file.status === 'error') {
        this.$message.error(`文件上传失败: ${info.file.msg} `);
      }
    },
    // 上传文件时调的保存接口
    saveBg(fileId, bgType) {
      postAction(this.url.saveBg, {
        proId: this.id,
        fileId: fileId,
        type: bgType
      }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.error(res.message)
        }
      })
    },
  }

}